import {natsClient} from "@/utils/nats_client";

/**
 * 上报邀请用户聊天
 * @param call 请求数据
 *
 * $report.${projectName}.{mainVersion}.{localClientId}.{module}.{directive}.{params | token | identifier}
 */
export function reqCallRing(call) {
    const {callee , caller} = call.call;
    return natsClient.req(`$request.$rv.v1.${caller.id}.singleChat.callRing.${callee.id}`, call, 30000)
}

export function subCallRing(calleeId , callback){
    natsClient.sub(`$request.$rv.v1.*.singleChat.callRing.${calleeId}` , callback)
}


export function unSubCallRing(calleeId){
    natsClient.unsub(`$request.$rv.v1.*.singleChat.callRing.${calleeId}`)
}


export function subCallRespond(callerId , callback){
    natsClient.sub(`$report.$rv.v1.*.singleChat.callRespond.${callerId}` , callback)
}

export function reportCallRespond(calleeId , callerId , respond){
    natsClient.pub(`$report.$rv.v1.${calleeId}.singleChat.callRespond.${callerId}` , respond)
}

export function unSubCallRespond(callerId){
    natsClient.unsub(`$report.$rv.v1.*.singleChat.callRespond.${callerId}`)
}

/**
 * 呼叫方向被呼叫方发布处理
 * @param calleeId 处理方id
 * @param callerId 接收方id
 * @param reply 处理数据
 */
export function reportCallReply(calleeId , callerId , reply){
    natsClient.pub(`$report.$rv.v1.${calleeId}.singleChat.callReply.${callerId}` , reply)
}

/**
 * 被呼叫方订阅处理
 * @param callerId 接收方id
 * @param callback 处理回调
 */
export function subCallReply(callerId , callback){
    natsClient.sub(`$report.$rv.v1.*.singleChat.callReply.${callerId}` , callback)
}

/**
 * 被呼叫方取消订阅处理
 * @param callerId 接收方id
 */
export function unSubCallReply(callerId){
    natsClient.unsub(`$report.$rv.v1.*.singleChat.callReply.${callerId}`)
}




export function reportWebRtcOffer(receiverId,callId,offer){
    natsClient.pub(`$report.$rv.v1.*.singleChat.offer.${receiverId}.${callId}`,offer)
}


export function subWebRtcOffer(receiverId,callId,callback){
    natsClient.sub(`$report.$rv.v1.*.singleChat.offer.${receiverId}.${callId}`,callback)
}


export function unSubWebRtcOffer(receiverId,callId){
    natsClient.unsub(`$report.$rv.v1.*.singleChat.offer.${receiverId}.${callId}`)
}


export function reportWebRtcAnswer(receiverId,callId,answer){
    natsClient.pub(`$report.$rv.v1.*.singleChat.answer.${receiverId}.${callId}`,answer)
}


export function subWebRtcAnswer(receiverId,callId,callback){
    natsClient.sub(`$report.$rv.v1.*.singleChat.answer.${receiverId}.${callId}`,callback)
}


export function unSubWebRtcAnswer(receiverId,callId){
    natsClient.unsub(`$report.$rv.v1.*.singleChat.answer.${receiverId}.${callId}`)
}


export function reportWebRtcCandidate(receiverId,callId,candidate){
    natsClient.pub(`$report.$rv.v1.*.singleChat.candidate.${receiverId}.${callId}`,candidate)
}


export function subWebRtcCandidate(receiverId,callId,callback){
    natsClient.sub(`$report.$rv.v1.*.singleChat.candidate.${receiverId}.${callId}`,callback)
}


export function unSubWebRtcCandidate(receiverId,callId){
    natsClient.unsub(`$report.$rv.v1.*.singleChat.candidate.${receiverId}.${callId}`)
}


export function reportWebRtcHangup(receiverId,callId , data){
    natsClient.pub(`$report.$rv.v1.*.singleChat.hangup.${receiverId}.${callId}` ,data)
}


export function subWebRtcHangup(receiverId,callId,callback){
    natsClient.sub(`$report.$rv.v1.*.singleChat.hangup.${receiverId}.${callId}`,callback)
}


export function unSubWebRtcHangup(receiverId,callId){
    natsClient.unsub(`$report.$rv.v1.*.singleChat.hangup.${receiverId}.${callId}`)
}
